import { createStore, applyMiddleware, compose } from 'redux';

import thunkMiddleware from 'redux-thunk';
import createSagaMiddleware from 'redux-saga';

import saga from './saga'
import reducer from './reducer';

//集成devtools的中间件
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({trace: true}) || compose

//应用中间件 两种方法 thunk || saga  

                    // 2. 创建sagaMiddleware中间件
const sagaMiddleware = createSagaMiddleware();

                    // 1. 引入thunkMiddleware中间件
const storeEnhancer = applyMiddleware(thunkMiddleware, sagaMiddleware);

                          //接受两个参数
const store = createStore(reducer, composeEnhancer(storeEnhancer))

//2.1
sagaMiddleware.run(saga)

export default store